package com.xiaoshuidi.cloud.module.contract.convert.contract;

import com.xiaoshuidi.cloud.module.contract.controller.admin.contract.vo.stay.*;
import com.xiaoshuidi.cloud.module.contract.dal.dataobject.contract.ContractMeterfeesDO;
import com.xiaoshuidi.cloud.module.contract.dal.dataobject.contract.ContractStayDO;
import com.xiaoshuidi.cloud.module.contract.service.contract.dto.ContractStayRoomEquipmentDTO;
import com.xiaoshuidi.cloud.module.rooms.vo.RoomEquipmentVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

/**
 * 交房退房 Convert
 *
 * @author 合房租赁
 */
@Mapper
public interface ContractStayConvert {

    ContractStayConvert INSTANCE = Mappers.getMapper(ContractStayConvert.class);

    ContractStayDO convert(ContractStayCreateReqVO bean);

    ContractStayRespVO convert(ContractStayDO bean);

    ContractStayDO convert(ContractStayUpdateReqVO bean);

    ContractStayPageRespVO convertBean2PageResp(ContractStayDO bean);

    ContractMeterfeesDO convert(ContractMeterfeesCreateReqVO bean);

    List<ContractMeterfeesDO> convertList(List<ContractMeterfeesCreateReqVO> list);

    ContractRentOutStayRespVO convertBean2RentOutStay(ContractStayDO bean);
    @Mappings({
            @Mapping(source="brand", target="brand", defaultExpression="java(\"\")"),
            @Mapping(source = "price", target = "price", qualifiedByName = "bigDecimalToStr")
    })


    ContractStayRoomEquipmentDTO convertRoomEquipment2RoomEquipmentDTO(RoomEquipmentVO bean);
    @Mappings({
            @Mapping(source="brand", target="brand", defaultExpression="java(\"\")"),
            @Mapping(source = "price", target = "price", qualifiedByName = "bigDecimalToStr")
    })
    List<ContractStayRoomEquipmentDTO> convertRoomEquipments2RoomEquipmentDTOs(List<RoomEquipmentVO> list);

    @Named("bigDecimalToStr")
    static String bigDecimalToStr(BigDecimal price){
        if (Objects.nonNull(price)){
            return price.toPlainString();
        }
        return "";
    }
}
